package com.example.gausspaper.repository;

import com.example.gausspaper.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User,String> {
    Optional<User> findById(String userId);

    /*@Query("select password from db_user where user_id = ?1")
    String checkIn(String id);

    @Query("select role_name from db_user where user_id = ?1")
    String checkRole(String id);*/

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO db_USER (user_id, password, name, role_name) VALUES (?1, ?2, ?3, ?4)",nativeQuery = true)
    void register(String id, String password, String name, String roleName);

//    @Transactional
//    @Modifying
//    @Query("delete from db_user where id = ?1")
//    void deleteUser(String id);
//
//    @Transactional
//    @Modifying
//    @Query("update db_user set role_name = ?2 where id = ?1")
//    void changeRole(String id, String role);
//
//    @Transactional
//    @Modifying
//    @Query("update db_user set password = ?2 where id = ?1")
//    void changePassword(String id, String password);
}
